package com.ruoyi.ebike.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ebike.vo.FlowIncomeVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ebike.domain.FlowRecords;
import com.ruoyi.ebike.service.IFlowRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 流水记录Controller
 * 
 * @author ruoyi
 * @date 2025-01-07
 */
@RestController
@RequestMapping("/ebikeUser/flowRecords")
public class FlowRecordsController extends BaseController
{
    @Autowired
    private IFlowRecordsService flowRecordsService;

    /**
     * 查询流水记录列表
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:flowRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlowRecords flowRecords)
    {
        startPage();
        List<FlowRecords> list = flowRecordsService.selectFlowRecordsList(flowRecords);
        return getDataTable(list);
    }

    /**
     * 导出流水记录列表
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:flowRecords:export')")
    @Log(title = "流水记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlowRecords flowRecords)
    {
        List<FlowRecords> list = flowRecordsService.selectFlowRecordsList(flowRecords);
        ExcelUtil<FlowRecords> util = new ExcelUtil<FlowRecords>(FlowRecords.class);
        util.exportExcel(response, list, "流水记录数据");
    }

    /**
     * 获取流水记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:flowRecords:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(flowRecordsService.selectFlowRecordsById(id));
    }

    /**
     * 新增流水记录
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:flowRecords:add')")
    @Log(title = "流水记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlowRecords flowRecords)
    {
        return toAjax(flowRecordsService.insertFlowRecords(flowRecords));
    }

    /**
     * 修改流水记录
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:flowRecords:edit')")
    @Log(title = "流水记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlowRecords flowRecords)
    {
        return toAjax(flowRecordsService.updateFlowRecords(flowRecords));
    }

    /**
     * 删除流水记录
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:flowRecords:remove')")
    @Log(title = "流水记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(flowRecordsService.deleteFlowRecordsByIds(ids));
    }

    /**
     * 获取收入数据
     */
    @PreAuthorize("@ss.hasPermi('ebikeUser:flowRecords:list')")
    @GetMapping("/income")
    public TableDataInfo getIncome(FlowRecords flowRecords)
    {
        List<FlowIncomeVO> list = flowRecordsService.getIncome(flowRecords);
        return getDataTable(list);
    }
}
